package testngReport;

import java.io.File;
import java.util.Date;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ResourceCDN;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class ExtentFactory {
	public static ExtentReports getInstance() {

		Date date = new Date();
		String form = String.format("%tF", date);
		String hour = String.format("%tH", date);
		String minute = String.format("%tM", date);
		String second = String.format("%tS", date);
		// 生成的路径以及文件名
		final String OUTPUT_FOLDER = "test-output/";
		final String FILE_NAME = "indexReport.html";

		// 文件夹不存在的话进行创建
		File reportDir = new File(OUTPUT_FOLDER);
		if (!reportDir.exists() && !reportDir.isDirectory()) {
			reportDir.mkdir();
		}

		ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(OUTPUT_FOLDER + FILE_NAME);
		// 设置静态文件的DNS
		htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);
		// 怎么样解决cdn.rawgit.com访问不了的情况
		htmlReporter.config().setResourceCDN(ResourceCDN.EXTENTREPORTS);
		htmlReporter.config().setDocumentTitle("Web UI 自动化测试报告");
		htmlReporter.config().setReportName("Web UI 功能自动化测试报告");
		htmlReporter.config().setChartVisibilityOnOpen(true);
		htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
		htmlReporter.config().setTheme(Theme.STANDARD);
		htmlReporter.config().setCSS(".node.level-1  ul{ display:none;} .node.level-1.active ul{display:block;}");
		htmlReporter.config().setEncoding("utf-8");
		ExtentReports extent = new ExtentReports();
		extent.attachReporter(htmlReporter);
		extent.setReportUsesManualConfiguration(true);
		extent.setSystemInfo("Selenium Version", "3.11.0");
		extent.setSystemInfo("Platform", "Windows");

		return extent;
	}
}